package cn.johnyu.controller;

import cn.johnyu.mapper.ProductMapper;
import org.example.commons.dto.ProductDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ProductController {
    @Autowired private ProductMapper productMapper;


    @GetMapping(value = "/products")
    public List<ProductDto> findAllProducts(){
        return productMapper.findAllProducts();
    }

    @GetMapping(value = "/products/{id}")
    public ProductDto findAllProducts(@PathVariable("id") int id){
        return productMapper.findProductById(id);
    }
}
